<template>
	<a-card :bordered="false">
		<a-form ref="searchFormRef" name="advanced_search" :model="searchFormState" class="ant-advanced-search-form">
			<a-row :gutter="24">
				<a-col :span="5">
					<a-form-item label="所属项目" name="projectCode">
						<ProjectSelect v-model:value="searchFormState.projectCode" />
					</a-form-item>
				</a-col>
				<a-col :span="5">
					<a-form-item label="手机号：" name="phoneNumber">
						<a-input v-model:value="searchFormState.phoneNumber" placeholder="请输入手机号" allow-clear />
					</a-form-item>
				</a-col>
				<a-col :span="5">
					<a-form-item label="姓名：" name="name">
						<a-input v-model:value="searchFormState.name" placeholder="请输入姓名" allow-clear />
					</a-form-item>
				</a-col>
				<a-col :span="5">
					<a-form-item label="身份证号：" name="idCard">
						<a-input v-model:value="searchFormState.idCard" placeholder="请输入身份证号" allow-clear />
					</a-form-item>
				</a-col>
				<a-col :span="4">
					<a-button type="primary" @click="tableRef.refresh(true)">查询</a-button>
					<a-button style="margin: 0 8px" @click="reset">重置</a-button>
				</a-col>
			</a-row>
		</a-form>
	</a-card>
	<a-card :bordered="false" class="mt-2">
		<s-table
			ref="tableRef"
			:columns="columns"
			:data="loadData"
			bordered
			:row-key="(record) => record.id"
			:tool-config="toolConfig"
		>
			<template #operator>
				<a-space>
					<a-button type="primary" @click="formRef.onOpen()" style="margin-right: 10%">
						<template #icon>
							<plus-outlined />
						</template>
						新增
					</a-button>
					<a-button type="primary" @click="upload.openUpload()">
						<template #icon>
							<import-outlined />
						</template>
						导入
					</a-button>
				</a-space>
			</template>
			<template #bodyCell="{ column, record }">
				<template v-if="column.dataIndex === 'action'">
					<a-popconfirm title="确定要删除此手机号吗？" @confirm="deleteModule(record.id)">
						<a-button type="link" danger size="small">删除</a-button>
					</a-popconfirm>
				</template>
			</template>
		</s-table>
	</a-card>
	<Form ref="formRef" @successful="tableRef.refresh(true)" />
	<Upload ref="upload" @successful="tableRef.refresh(true)" />
</template>

<script setup name="phoneFilter">
	import Form from '@/views/tjzy/phone/filter/form.vue'
	import phoneFilterApi from '@/api/tjzy/phone/filter/phoneFilterApi'
	import Upload from '@/views/tjzy/phone/filter/upload.vue'
	import ProjectSelect from '@/components/Tjzy/Project/index.vue'

	const upload = ref()
	const searchFormState = ref({
		projectCode: undefined,
		phoneNumber: undefined,
		name: undefined,
		idCard: undefined
	})
	const searchFormRef = ref()
	const tableRef = ref()
	const formRef = ref()
	const toolConfig = { refresh: true, height: true, columnSetting: false, striped: false }
	const columns = [
		{
			title: '项目名称',
			dataIndex: 'projectName'
		},
		{
			title: '姓名',
			dataIndex: 'name'
		},
		{
			title: '身份证号',
			dataIndex: 'idCard'
		},
		{
			title: '手机号',
			dataIndex: 'phoneNumber'
		},
		{
			title: '备注',
			dataIndex: 'remark',
			ellipsis: true
		},
		{
			title: '创建人',
			dataIndex: 'createUserName'
		},
		{
			title: '创建时间',
			dataIndex: 'createTime',
			ellipsis: true
		},
		{
			title: '操作',
			dataIndex: 'action',
			align: 'center'
		}
	]

	const loadData = (parameter) => {
		searchFormState.value.current = parameter.current
		searchFormState.value.size = parameter.size
		return phoneFilterApi.pageList(searchFormState.value).then((res) => {
			return res
		})
	}

	// 删除
	const deleteModule = (id) => {
		phoneFilterApi.delete(id).then(() => {
			tableRef.value.refresh(true)
		})
	}

	const reset = () => {
		searchFormRef.value.resetFields()
		tableRef.value.refresh(true)
	}
</script>
